/*
 * File:   ChessBoard.h
 * Author: crash
 *
 * Created on February 28, 2011, 7:53 PM
 */

#ifndef CHESSBOARD_H
#define	CHESSBOARD_H

#include "IBoardListener.h"
#include "Typesfwd.h"
#include "pieces/ChessPiece.h"
#include <boost/unordered_map.hpp>
#include <set>

namespace model
{
	class ChessBoard
	{
	public:
            typedef boost::unordered_map<const Location, globals::cPiece> boardMap;
            typedef boardMap::const_iterator const_map_iterator;
            typedef boardMap::iterator map_iterator;

            static const int SIZE = 8;
            ChessBoard();
            ChessBoard(const ChessBoard&);
            ChessBoard& operator =(const ChessBoard&);

            void addBoardListener(const IBoardListener*);

            void removeBoardListener(const IBoardListener*);

            globals::cPiece setPieceAt(const Location&, const globals::cPiece&);

            globals::cPiece removePieceAt(const Location&);

            globals::cPiece movePiece(const Location& from, const Location& to);

            const globals::cPiece& getPieceAt(const Location&) const;

            bool hasLocation(const Location&) const;

            void clear();

            void switchTurn();

            bool isLightTurn() const;

            const boardMap& getGrid() const;

            globals::pieceList getPieces(bool lightTeam) const;

            const globals::cPiece getKing(bool lightTeam) const;
	protected:
            void fireBoardChanged(const Location&, const globals::cPiece&) const;

        private:
            typedef std::set<const IBoardListener*> listenerSet;
            boardMap grid;
            listenerSet listeners;
            bool lightTurn;

            void copy(const ChessBoard&);

	};
} // namespace model

#endif	/* CHESSBOARD_H */
